<template>
	<view class="content">
		<view class="avatar" :style="{background: `url(${imgPath}storage/home/my_bg.png)`}">
			<view>
				<u-avatar :src="avatarUrl" size="80" @click="login"></u-avatar>
				<view class="name" v-if="nickName">
					{{nickName}}
				</view>
				<view class="name noLogin" v-else>
					点击授权>>
				</view>
			</view>
		</view>
		<view class="box">
			<view class="title">
				我的服务
			</view>
			<view class="list">
				<view class="item" @click="goParyOrders">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my1.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							祈福订单
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="goNafuOrders">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my2.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							纳福订单
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="goSesameoilOrders">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/addsesameoil.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							灯杆冠名订单
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="goPary">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my3.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							去寺庙
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="goSesameoil">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my4.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							去灯杆冠名
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="goDeliveryaddress">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my5.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							收货地址
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="item" @click="open">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my6.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							清除缓存
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<button open-type="contact" class="item1" style="border-radius: 0;">
					<view class="left">
						<view class="img">
							<u--image :showLoading="true" :src="imgPath + 'storage/home/my7.png'" width="50rpx"
								height="50rpx"></u--image>
						</view>
						<view class="text">
							客服
						</view>
					</view>
					<view class="right">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</button>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popupview">
				<view class="close" @click="close">
					<u-icon name="close" color="#fff" size="28" bold></u-icon>
				</view>
				<view class="popup-title">
					清理缓存
				</view>
				<view class="popup-text">
					确定要清理缓存？
				</view>
				<view class="popup-btn">
					<view class="left" @click="close">
						取消
					</view>
					<view class="right" @click="clearSubmit">
						确认
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				avatarUrl: '',
				nickName: '去登录',
				minisystemInfo: ''
			}
		},
		onShow() {
			this.loginStatic()
		},
		onLoad() {
			uni.getStorage({
				key: 'minisystemInfo',
				success: (res) => {
					this.minisystemInfo = res.data
				}
			})
		},
		onShareAppMessage(e) {
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let currentPage = routes[routes.length - 1].route;
			let shareobj = {
				title: this.minisystemInfo.sub_title, //分享的标题
				path: currentPage, //好友点击分享之后跳转的页面
				imageUrl: this.minisystemInfo.url, //内容图片
			}
			return shareobj //一定要返回对象
		},
		methods: {
			login() {
				if (getToken()) return
				var that = this;
				uni.showLoading({
					title: '登录中...'
				});
				uni.login({
					provider: 'weixin', //使用微信登录
					success: function(loginRes) {
						that.$api.login({
							code: loginRes.code
						}).then(res => {
							console.log(1);
							that.$store.commit('login/setToken', res.data)
							that.loginStatic()
							uni.hideLoading()
						})
					}
				});
			},
			goParyOrders() {
				uni.navigateTo({
					url: '/subpackageA/paryorders/paryorders'
				})
			},
			goNafuOrders() {
				uni.navigateTo({
					url: '/subpackageA/nafuorders/nafuorders'
				})
			},
			goSesameoilOrders() {
				uni.navigateTo({
					url: '/subpackageB/sesameoilorder/sesameoilorder'
				})
			},
			goPary() {
				uni.switchTab({
					url: '/pages/templelist/templelist'
				})
			},
			goSesameoil() {
				uni.navigateTo({
					url: '/subpackageA/sesameoil/sesameoil'
				})
			},
			goDeliveryaddress() {
				uni.navigateTo({
					url: '/subpackageA/deliveryaddress/deliveryaddress'
				})
			},
			open() {
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			loginStatic() {
				if (getToken()) {
					this.avatarUrl = 'http://pray.veac.cn/storage/avatar.png'
					this.nickName = '微信用户'
				} else {
					this.avatarUrl = this.imgPath + 'storage/home/on_login.png'
					this.nickName = ''
				}
			},
			clearSubmit() {
				this.close()
				uni.showLoading({
					title: '清除缓存...'
				});

				setTimeout(function() {
					uni.hideLoading();
				}, 800);
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		// height: 100%;
		background-color: #FEF1DC;
		padding-bottom: 170rpx;
	}

	.avatar {
		height: 490rpx;
		box-sizing: border-box;
		padding-top: 220rpx;
		display: flex;
		justify-content: center;
	}

	.name {
		padding-top: 30rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 32rpx;
		color: #111111;
		line-height: 44rpx;
		text-align: center;
		font-style: normal;
	}

	.box {
		padding: 60rpx 60rpx 0 60rpx;
	}

	.title {
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 32rpx;
		color: #111111;
		line-height: 44rpx;
		text-align: left;
		font-style: normal;
	}

	.list {
		.item1::after {
			border: none;
		}

		.item1 {
			display: flex;
			justify-content: space-between;
			padding: 48rpx 0 30rpx;
			background-color: transparent;
			border-bottom: 2rpx solid #d3d3d3;

			.left {
				display: flex;

				.img {
					width: 50rpx;
					height: 50rpx;
					// background: #FFBFC4;
					// border-radius: 50%;
					margin-right: 20rpx;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
					line-height: 50rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.right {}
		}

		.item {
			display: flex;
			justify-content: space-between;
			padding: 48rpx 0 30rpx;
			border-bottom: 2rpx solid #d3d3d3;

			.left {
				display: flex;

				.img {
					width: 50rpx;
					height: 50rpx;
					// background: #FFBFC4;
					// border-radius: 50%;
					margin-right: 20rpx;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
					line-height: 50rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.right {}
		}
	}

	.popupview {
		position: relative;
		width: 570rpx;
		height: 440rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		padding: 0 50rpx;

		.close {
			width: 90rpx;
			height: 90rpx;
			position: absolute;
			bottom: -150rpx;
			left: 50%;
			transform: translateX(-50%);
			border: 8rpx solid white;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.popup-title {
			padding-top: 70rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #111111;
			line-height: 44rpx;
			text-align: center;
			font-style: normal;
		}

		.popup-text {
			padding-top: 70rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #AAAAAA;
			line-height: 40rpx;
			text-align: center;
			font-style: normal;
		}

		.popup-btn {
			padding-top: 72rpx;
			display: flex;
			justify-content: space-around;

			.left,
			.right {
				width: 220rpx;
				height: 84rpx;
				border-radius: 42rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 84rpx;
				text-align: center;
				font-style: normal;
			}

			.left {
				background: #DDDDDD;
			}

			.right {
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
			}
		}

	}

	.noLogin {
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 32rpx;
		color: #2863FF;
		line-height: 44rpx;
		text-align: center;
		font-style: normal;
	}
</style>